//
//  UINavigationItem.swift
//  Automobile
//
//  Created by erkebulan elzhan on 7/24/20.
//  Copyright © 2020 erkebulan elzhan. All rights reserved.
//

import UIKit


extension UINavigationItem {

 func setTitle(title:String, subtitle:String) {
        
    let titleLbl = UILabel()
        titleLbl.text = title
        titleLbl.font = UIFont.systemFont(ofSize: 17, weight: .bold)
        titleLbl.sizeToFit()

        let subtitleLbl = UILabel()
        subtitleLbl.text = subtitle
        subtitleLbl.font = UIFont.systemFont(ofSize: 12)
        subtitleLbl.textAlignment = .center
        subtitleLbl.textColor = .gray
        subtitleLbl.sizeToFit()



        let stackView = UIStackView(arrangedSubviews: [titleLbl, subtitleLbl])
        stackView.distribution = .equalCentering
        stackView.axis = .vertical
        stackView.alignment = .center

        let width = max(titleLbl.frame.size.width, subtitleLbl.frame.size.width)
        stackView.frame = CGRect(x: 0, y: 0, width: width, height: 35)
        stackView.backgroundColor = .white

        titleLbl.sizeToFit()
        subtitleLbl.sizeToFit()
        self.titleView = stackView
    }
    
    func simpleNavBar (title: String, backButton: UIBarButtonItem) {
        largeTitleDisplayMode = .never
        self.title = title
        hidesBackButton = true
        self.leftBarButtonItem = backButton
    }
}
extension UINavigationBar {
    func defaultNavBar () {
        setValue(true, forKey: "hidesShadow")
    }
}

